package com.jxpanda.infrastructure.core.tollkit;


import com.jxpanda.infrastructure.core.formatter.DecimalFormatter;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.stream.Stream;

public class DecimalKit {

    public static String toCNY(BigDecimal decimal) {
        return "￥" + DecimalFormatter.TWO_DECIMAL.format(decimal);
    }

    public static String format(BigDecimal decimal) {
        return DecimalFormatter.TWO_DECIMAL.format(decimal);
    }

    public static String format(BigDecimal decimal, String pattern) {
        return new DecimalFormat(pattern).format(decimal);
    }

    public static BigDecimal sigma(Stream<BigDecimal> stream) {
        return stream.reduce(BigDecimal.ZERO, BigDecimal::add);
    }

}
